<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Return the servers to which this manager is connected</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-driver-manager.getreadpreference.html">« MongoDB\Driver\Manager::getReadPreference</a></li>
      <li style="float: right;"><a href="mongodb-driver-manager.getwriteconcern.html">MongoDB\Driver\Manager::getWriteConcern »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-driver-manager.html">MongoDB\Driver\Manager</a></li>
    <li>Return the servers to which this manager is connected</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-driver-manager.getservers" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\Manager::getServers</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Manager::getServers</span> &mdash; <span class="dc-title">Return the servers to which this manager is connected</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-manager.getservers-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\Manager::getServers</strong></span>(): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   Returns an <span class="type">array</span> of <span class="classname"><a href="class.mongodb-driver-server.html" class="classname">MongoDB\Driver\Server</a></span>
   instances to which this manager is connected.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    Since the driver connects to the database lazily, this method may return an
    empty <span class="type">array</span> if called before executing an operation on the
    <span class="classname"><a href="class.mongodb-driver-manager.html" class="classname">MongoDB\Driver\Manager</a></span>.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-manager.getservers-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-manager.getservers-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an <span class="type">array</span> of <span class="classname"><a href="class.mongodb-driver-server.html" class="classname">MongoDB\Driver\Server</a></span>
   instances to which this manager is connected.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-manager.getservers-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="simplelist">
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li>
  </ul>
 </div>



 <div class="refsect1 examples" id="refsect1-mongodb-driver-manager.getservers-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1304">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\Driver\Manager::getServers()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://localhost:27017"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;The&nbsp;driver&nbsp;connects&nbsp;to&nbsp;the&nbsp;database&nbsp;server&nbsp;lazily,&nbsp;so&nbsp;Manager::getServers()<br />&nbsp;*&nbsp;may&nbsp;initially&nbsp;return&nbsp;an&nbsp;empty&nbsp;array.&nbsp;*/<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServers</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">$command&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Command</span><span style="color: #007700">([</span><span style="color: #DD0000">'ping'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">executeCommand</span><span style="color: #007700">(</span><span style="color: #DD0000">'db'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$command</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServers</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(0) {
}
array(1) {
  [0]=&gt;
  object(MongoDB\Driver\Server)#3 (10) {
    [&quot;host&quot;]=&gt;
    string(9) &quot;localhost&quot;
    [&quot;port&quot;]=&gt;
    int(27017)
    [&quot;type&quot;]=&gt;
    int(1)
    [&quot;is_primary&quot;]=&gt;
    bool(false)
    [&quot;is_secondary&quot;]=&gt;
    bool(false)
    [&quot;is_arbiter&quot;]=&gt;
    bool(false)
    [&quot;is_hidden&quot;]=&gt;
    bool(false)
    [&quot;is_passive&quot;]=&gt;
    bool(false)
    [&quot;last_hello_response&quot;]=&gt;
    array(8) {
      [&quot;isWritablePrimary&quot;]=&gt;
      bool(true)
      [&quot;maxBsonObjectSize&quot;]=&gt;
      int(16777216)
      [&quot;maxMessageSizeBytes&quot;]=&gt;
      int(48000000)
      [&quot;maxWriteBatchSize&quot;]=&gt;
      int(1000)
      [&quot;localTime&quot;]=&gt;
      object(MongoDB\BSON\UTCDateTime)#4 (1) {
        [&quot;milliseconds&quot;]=&gt;
        int(1447267964517)
      }
      [&quot;maxWireVersion&quot;]=&gt;
      int(3)
      [&quot;minWireVersion&quot;]=&gt;
      int(0)
      [&quot;ok&quot;]=&gt;
      float(1)
    }
    [&quot;round_trip_time&quot;]=&gt;
    int(554)
  }
}
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongodb-driver-manager.getservers-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="classname"><a href="class.mongodb-driver-server.html" class="classname">MongoDB\Driver\Server</a></span></li>
   <li class="member"><span class="function"><a href="mongodb-driver-manager.selectserver.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::selectServer()</a> - Select a server matching a read preference</span></li>
  </ul>
 </div>


</div></div></div></body></html>